package com.yuki.controller;

import com.yuki.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

@Controller
@Configuration
public class UserController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping(value = "/query/{id}")
    @ResponseBody
    public User query(@PathVariable("id") Integer id) {
        return restTemplate.getForEntity("http://eureka-provider/query/{id}", User.class, id).getBody();
    }

    @GetMapping(value = "/delete/{id}")
    @ResponseBody
    public String del(@PathVariable("id") Integer id) {
        return restTemplate.getForEntity("http://eureka-provider/delete/{id}", String.class, id).getBody();
    }

    @GetMapping(value = "/save/{id}/{userName}/{passWord}")
    @ResponseBody
    public String save(@PathVariable("id") Integer id, @PathVariable("userName") String userName, @PathVariable("passWord") String passWord) {
        return restTemplate
                .getForEntity("http://eureka-provider/save/{id}/{userName}/{passWord}", String.class, id, userName, passWord)
                .getBody();
    }
}
